using UnityEngine;

public class Obstacle : MonoBehaviour
{
	public AudioClip soundHit;

	private AudioSource soundSource;

	public bool angularVelocitySound;

	private Vector3 prevVelocity = Vector3.zero;

	private Vector3 prevAngularVelocity = Vector3.zero;

	private void Start()
	{
		soundSource = base.gameObject.GetComponent<AudioSource>();
		if (soundSource == null)
		{
			soundSource = base.gameObject.AddComponent<AudioSource>();
		}
		soundSource.clip = soundHit;
		soundSource.loop = false;
		soundSource.rolloffMode = AudioRolloffMode.Linear;
		soundSource.maxDistance = 30f;
		soundSource.dopplerLevel = 0.1f;
	}

	private void OnCollisionEnter()
	{
		float volume = (base.GetComponent<Rigidbody>().velocity - prevVelocity).magnitude * 0.02f;
		Audio.PlayShotSound(soundHit, volume, soundSource);
	}

	private void FixedUpdate()
	{
		if (angularVelocitySound)
		{
			float magnitude = (base.GetComponent<Rigidbody>().angularVelocity - prevAngularVelocity).magnitude;
			if (magnitude > 0.8f)
			{
				float volume = magnitude * 0.5f;
				Audio.PlayShotSound(soundHit, volume, soundSource);
			}
		}
		prevVelocity = base.GetComponent<Rigidbody>().velocity;
		prevAngularVelocity = base.GetComponent<Rigidbody>().angularVelocity;
	}
}
